package com.weic.manager.utils;

import com.weic.manager.vo.SuperVO;

import java.util.Collection;
import java.util.Dictionary;
import java.util.Map;
import java.util.Random;

public class WUtils {

    private static String SOURCE_STR = "abcdefghijklmnopqrstuvwxyz0123456789";

    public static void  setUUID(SuperVO superVO){
        superVO.setPkValue(createUUID());
    }

    /**
     * 生成32位uuid
     * @return
     */
    public static String createUUID(){
        Random random = new Random();
        String[] sourceArr = SOURCE_STR.split("");
        StringBuffer strBuf = new StringBuffer();
        for(int i=0;i<32;i++){
            strBuf.append(sourceArr[random.nextInt(35)]);
        }
        return strBuf.toString();

    }

    /**
     * 判断对象是否为空
     * @param value
     * @return
     */
    public static boolean isEmpty(Object value) {
        if(value == null) {
            return true;
        }
        if((value instanceof String) && (((String) value).trim().length() <= 0)) {
            return true;
        }
        if((value instanceof Object[]) && (((Object[]) value).length <= 0)) {
            return true;
        }
        // 鍒ゆ柇鏁扮粍涓殑鍊兼槸鍚﹀叏閮ㄤ负绌簄ull.
        if(value instanceof Object[]) {
            Object[] t = (Object[]) value;
            for(int i = 0; i < t.length; i++) {
                if(t[i] != null) {
                    return false;
                }
            }
            return true;
        }
        if((value instanceof Collection) && ((Collection) value).size() <= 0) {
            return true;
        }
        if((value instanceof Dictionary) && ((Dictionary) value).size() <= 0) {
            return true;
        }
        if((value instanceof Map) && ((Map) value).size() <= 0) {
            return true;
        }
        if((value instanceof StringBuffer) && (((StringBuffer) value).length() <= 0)) {
            return true;
        }
        return false;
    }


}
